package com.example.recruitment.config;

import com.example.recruitment.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")  // 拦截所有请求
                .excludePathPatterns(    // 排除不需要拦截的路径
                    "/login",            // 登录页面
                    "/register",         // 注册页面
                    "/error",            // 错误页面
                    "/static/**",        // 静态资源
                    "/css/**",           // 静态资源
                    "/js/**",            // 静态资源
                    "/images/**",        // 静态资源
                    "/fonts/**",         // 静态资源
                    "/favicon.ico"       // 图标
                );
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
    }
} 